from .base import KeyframeStrategy
from typing import List, Set
from ..models import FrameData
import numpy as np
from scipy.signal import argrelextrema


class LocalMaximaStrategy(KeyframeStrategy):
    def __init__(self, len_window: int):
        self.len_window = len_window

    @staticmethod
    def _smooth(x, window_len=13, window='hanning'):
        # 原有smooth函数实现
        pass

    def detect(self, frames: List[FrameData]) -> Set[int]:
        diffs = np.array([f.diff for f in frames])
        smoothed = self._smooth(diffs, self.len_window)
        maxima = argrelextrema(smoothed, np.greater)[0]
        return {frames[i].id for i in maxima}